/**
 * PC.java
 * @author: liuex
 * 2008-3-9 ����11:51:24
 *
 * note: 
 */
package org.lex.math.pc;

/**
 * 
 */
public class PC {
	/**
	 * P(n,r)
	 * 
	 * @param n
	 * @param r
	 * @return
	 */
	public static int permutation(int n, int r) {
		int p = 1;
		for (int i = n - r + 1; i <= n; i++)
			p *= i;
		return p;
	}

	/**
	 * C(n,r)
	 * 
	 * @param n
	 * @param r
	 * @return
	 */
	public static int combination(int n, int r) {
		int c = 1;
		for (int i = n; i > r; i--)
			c *= i;
		for (int i = n - r; i > 1; i--)
			c /= i;
		return c;
	}

	/**
	 * n!
	 * 
	 * @param n
	 * @return
	 */
	public static int factorial(int n) {
		int f = 0;
		for (int i = n; i > 1; i--)
			f *= i;
		return f;
	}
}
